package io.renren.modules.basic.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.basic.dao.MtCcWarehousPositionRelatDao;
import io.renren.modules.basic.entity.MtCcProductEntity;
import io.renren.modules.basic.entity.MtCcWarehousPositionRelatEntity;
import io.renren.modules.basic.service.MtCcWarehousPositionRelatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;



@Service("mtCcWarehousPositionRelatService")
public class MtCcWarehousPositionRelatServiceImpl extends ServiceImpl<MtCcWarehousPositionRelatDao, MtCcWarehousPositionRelatEntity> implements MtCcWarehousPositionRelatService {

    @Autowired
    private MtCcWarehousPositionRelatDao mtCcWarehousPositionRelatDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = String.valueOf(params.get("key"));
        IPage<MtCcWarehousPositionRelatEntity> page =null;
        if (key.equals("")){
             page = this.page(
                    new Query<MtCcWarehousPositionRelatEntity>().getPage(params),
                    new QueryWrapper<MtCcWarehousPositionRelatEntity>().orderByDesc("id")
            );
        }else {
            String keyFeature = String.valueOf(params.get("key")).substring(1, 2);
            if (keyFeature.equals(".")){
                page = this.page(
                        new Query<MtCcWarehousPositionRelatEntity>().getPage(params),
                        new QueryWrapper<MtCcWarehousPositionRelatEntity>().likeRight("product_code",key)
                );
            }else {
                page = this.page(
                        new Query<MtCcWarehousPositionRelatEntity>().getPage(params),
                        new QueryWrapper<MtCcWarehousPositionRelatEntity>().eq("product_name",key)
                );
            }
        }


        return new PageUtils(page);
    }

    @Override
    public PageUtils queryCount(Map<String, Object> params) {
        /*IPage<MtCcWarehousPositionRelatEntity> page =this.page(
                new Query<MtCcWarehousPositionRelatEntity>().getPage(params),
                 new QueryWrapper<MtCcWarehousPositionRelatEntity>()
        );*/
        String productCode = String.valueOf(params.get("key"));
        List<MtCcWarehousPositionRelatEntity> mtCcWarehousPositionRelatEntities = mtCcWarehousPositionRelatDao.selectCountByCode(productCode);
        IPage<MtCcWarehousPositionRelatEntity> page =new Page<>();
        page.setRecords(mtCcWarehousPositionRelatEntities);
        return new PageUtils(page);
    }

    @Override
    public List<MtCcWarehousPositionRelatEntity> selectNumForCheckOut(Map<String, Object> params) {
        return mtCcWarehousPositionRelatDao.selectNumForCheckOut(params);
    }

    @Override
    public MtCcWarehousPositionRelatEntity selectInsidePosition() {
        return mtCcWarehousPositionRelatDao.selectInsidePosition();
    }

}